package com.dashu.device.netty.ipml;


import com.dashu.base.enums.device.ModuleType;
import com.dashu.base.utils.ToEntityAnStr;
import com.dashu.device.api.CQ.CQInsideServerApi;
import com.dashu.device.bean.CQ.CQBaseResp;
import com.dashu.device.service.CQ.CQInsideInsideService;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.util.TextUtils;

@Slf4j
public class CQServerImpl {

    private CQInsideServerApi cqServerApi = new CQInsideInsideService();

    public CQServerImpl(String msg, ChannelHandlerContext ctx, ModuleType moduleType) {
        try {
            CQBaseResp req = ToEntityAnStr.string2Obj(msg, CQBaseResp.class);
            System.out.println(ToEntityAnStr.obj2String(req));
            //不处理不带sn设备
            if (req == null || TextUtils.isEmpty(req.getSn()))
                return;
            switch (req.getCmd()) {
                case 2:
                    cqServerApi.heartbeat(ctx, req, 0);
                    break;
                case 256:
                    cqServerApi.register(ctx, req);
                    break;
                case 258:
                    cqServerApi.compared(ctx, req, msg);
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
